import {useState} from 'react'
// 兄弟组件的通信-状态提升原理
function Son1({onGetName}) {
  const name = 'jack'
  return (
    <div>
      <span>我是Son1</span>
      <button onClick={() => onGetName(name)}>点击传递name</button>
    </div>
  )
}
function Son2(props) {
  
  return <div>我是Son2: {props.name}</div>
}

function App() {
  const [name, setName] = useState('')
  const getName = (name) => {
    setName(name)
    console.log(name)
  }
  return (
    <div className="App">
      <Son1 onGetName={ getName }></Son1>
      <Son2 name={name}></Son2>
    </div>
  )
}

export default App;









